import greenfoot.*;

public class Records extends World
{
    private UserI user;                         //User information.
    private UserInfo info;
    private java.util.List users;
    private SimpleTimer t = new SimpleTimer();  //Timer.
    private int puntaje;

    /**
     * Records Constructor.
     */
    public Records( int punt)
    {          
        super(600, 500, 1); 
        t.mark();
        puntaje=punt;
    }

    public void act()
    {
        int i;
        Lifes m;
        users = UserInfo.getTop( 5);
        
        if ( UserInfo.isStorageAvailable()) {               //Storage the scores.
            UserInfo myInfo = UserInfo.getMyInfo();
            if (puntaje > myInfo.getScore()) {
                myInfo.setScore( puntaje);
                myInfo.store();
            }
        }
        if(users != null)
        {
            for( i = 0; i < users.size(); i++)              //Shows the scores.
            {
                info = ( UserInfo)users.get( i);
                user = new UserI( ( i + 1) + "=" + info.getUserName(), info.getScore(), info.getUserImage());
                user.addToWorld( 70 + 50 * i, this);
            }
            if( UserInfo.getMyInfo().getRank() > 0)
                m = new Lifes( UserInfo.getMyInfo().getRank(), "Users: ");
            else
                m = new Lifes( 0, "There aren't records here...");
            this.addObject( m, 20 + ( m.getImage().getWidth()/2), 450);
        }
        else
        {
            m = new Lifes(0, "There aren't records here...");       //If there aren't scores...
            this.addObject( m, 300, 250);
        }
        
        if( t.millisElapsed() > 5000)
            Greenfoot.setWorld(new Menu(0) );
    }
}